package exercise;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class LCode2682 {
    public int[] circularGameLosers(int n, int k) {
        Map<Integer, Boolean> map = new HashMap<>();
        for (int i = 2; i <= n; i++) {
            map.put(i, false);
        }

        int step = 1;
        for (int i = 1; i <= n;) {
            i = (i + step * k) %  n == 0 ? n : (i + step * k) %  n;
            if (!map.containsKey(i)) {
                break;
            }
            map.remove(i);
            step++;
        }
        int[] ans = new int[map.size()];
        int index = 0;

        for (int i = 1; i <= n; i++) {
            if (map.containsKey(i)) {
                ans[index++] = i;
            }
        }

        return ans;
    }


    public static void main(String[] args) {
        LCode2682 lCode2682 = new LCode2682();
        System.out.println(Arrays.toString(lCode2682.circularGameLosers(2, 1)));
    }
}
